<template>
	<view>
		<!-- 搜索框 -->
		<view @click="addFriend">
			<u-search shape="square" placeholder="账号/手机号" margin="30rpx" :showAction="false" :disabled="true" style="pointer-events:none;"></u-search>
		</view>
		
		<view class="list-content">
			<view v-for="(lists, idx) in friendApplyLists" :key="idx">
				<u-cell-group>
					<u-cell-item style="height: 140rpx;" :title-style="titleStyle" :title="lists.isInitiator == '我添加对方' ? lists.tInfo.nickname : lists.fInfo.nickname"
					 @click="groupClick(lists)" :label-style="labelStyle" :label="(lists.isInitiator == '我添加对方' ? '我：'+ lists.msg : lists.msg )"
					  hover-class="message-hover-class" :arrow='false' :value="lists.isInitiator == '我添加对方'? (lists.isInitiator == '我添加对方' ? '↗ ' + (lists.status==2?'已添加':'等待验证') : '前往验证') : (lists.status==2?'已添加':'前往验证') " :value-style="valueStyle">
						<template #icon>
							<image mode="aspectFill" 
								:src="lists.isInitiator == '我添加对方' ? lists.tInfo.miniAvatar : lists.fInfo.miniAvatar" 
								:style="{ width: '54px', height: '54px', borderRadius: '10rpx', marginRight: '10px' }"/>
						</template>
					</u-cell-item>
					<view style="position: absolute; bottom: 34rpx; right: 40rpx; font-size: 12px; color: #999;">
						{{lists.createTime}}
					</view>
				</u-cell-group>
			</view>
		</view>
	</view>
</template>

<script>
import { api } from '../../api/api';
import { myRequest } from '../../util/api';
	export default {
		data() {
			return {
				labelStyle: {
					width: '300rpx',
					marginTop: '0rpx',
					whiteSpace: 'nowrap',
					overflow: 'hidden',
					textOverflow: 'ellipsis',
				},
				titleStyle: {
					width: '420rpx',
					color: 'black',
					fontSize: '34rpx',
					paddingTop: '10rpx',
				},
				friendApplyLists: {},
				valueStyle: {
					height: '50rpx',
					lineHeight: '50rpx',
					width: '200rpx',
				}
			};
		},
		methods: {
			addFriend() {
				uni.navigateTo({
					url: '/pages/addFriend/addFriend'
				});
			},
			groupClick(result) {
				console.log(result)
				let isFriend = 0; //默认
				if( result.status == 2 ){ //已同意
					isFriend = 1;
				} else if(result.status == 3 && result.isInitiator != '我添加对方'){ // 拒绝
					isFriend = -1;
				} else if(result.status == 1 && result.isInitiator == '我添加对方'){ // 待对方处理
					isFriend = 2;
				} else if(result.status == 1 && result.isInitiator != '我添加对方'){ // 待我处理
					isFriend = 3;
				}
				let id = result.fInfo.id;
				let miniAvatar = result.fInfo.miniAvatar;
				let nickname = result.fInfo.nickname;
				let area = result.fInfo.area;
				let signature = result.fInfo.signature;
				let sex = result.fInfo.sex;
				if (result.isInitiator == '我添加对方') {
					id = result.tInfo.id;
					miniAvatar = result.tInfo.miniAvatar;
					nickname = result.tInfo.nickname;
					area = result.tInfo.area;
					signature = result.tInfo.signature;
					sex = result.tInfo.sex;
				}
				console.log('状态：'+isFriend)
				this.$u.route('pages/searchResult/searchResult', {
					id: id,
					miniAvatar: miniAvatar,
					nickname: nickname,
					area: area,
					signature: signature,
					isFriend: isFriend,
					sex: sex,
					source: 'apply', //来源
				});
			},
			
		},
		async onLoad() {
			const response = await myRequest({
				url: api.applyFriendList,
				success: (res) => {
					if (res.data.code == 200 && res.data.httpCode == 200){
						this.friendApplyLists = res.data.data
					}
				}
			});
		}
	}
</script>

<style lang="scss">
	.list-content{
		
	}
</style>
